<%--
  Created by IntelliJ IDEA.
  User: zhanglh
  Date: 2019/9/10/010
  Time: 15:05
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <meta charset="utf-8">
    <title>持明法洲后台管理系统</title>
    <link rel="stylesheet" href="${pageContext.request.contextPath}/layui/css/layui.css">
    <script type="text/javascript" src="${pageContext.request.contextPath}/js/jquery-1.12.4.js"></script>
    <script type="text/javascript" src="${pageContext.request.contextPath}/layui/layui.js"></script>
</head>
<body class="layui-layout-body">
<div class="layui-layout layui-layout-admin">
    <div class="layui-header">
        <div class="layui-logo">持明法洲后台管理系统</div>
        <!-- 头部区域（可配合layui已有的水平导航） -->
        <%--<ul class="layui-nav layui-layout-left">
            <li class="layui-nav-item"><a href="">控制台</a></li>
            <li class="layui-nav-item"><a href="">商品管理</a></li>
            <li class="layui-nav-item"><a href="">用户</a></li>
            <li class="layui-nav-item">
                <a href="javascript:;">其它系统</a>
                <dl class="layui-nav-child">
                    <dd><a href="">邮件管理</a></dd>
                    <dd><a href="">消息管理</a></dd>
                    <dd><a href="">授权管理</a></dd>
                </dl>
            </li>
        </ul>--%>
        <ul class="layui-nav layui-layout-right">
            <li class="layui-nav-item">
                <a href="javascript:;">
                    <img src="http://t.cn/RCzsdCq" class="layui-nav-img">
                    ${sessionScope.admin.username}
                </a>
                <dl class="layui-nav-child">
                    <dd><a href="">基本资料</a></dd>
                    <dd><a href="">安全设置</a></dd>
                </dl>
            </li>
            <li class="layui-nav-item"><a href="${pageContext.request.contextPath}/admin/logout">退了</a></li>
        </ul>
    </div>

    <div class="layui-side layui-bg-black">
        <div class="layui-side-scroll">
            <!-- 左侧导航区域（可配合layui已有的垂直导航） -->
            <ul class="layui-nav layui-nav-tree" lay-filter="menu-nav" id="menu">

            </ul>
        </div>
    </div>

    <div class="layui-body">
        <!-- 内容主体区域 -->
        <div style="padding: 15px;">
            <div class="layui-tab layui-tab-brief layui-tab-card" lay-allowClose="true" lay-filter="myTab">
                <ul class="layui-tab-title ">
                    <li class="layui-this" lay-id="all">欢迎</li>
                </ul>
                <div class="layui-tab-content">
                    <div class="layui-tab-item layui-show">
                        <marquee direction="right" behavior="alternate" onMouseOut="this.start()"
                                 onMouseOver="this.stop()">
                            <div>
                                <h1></i>&nbsp;&nbsp; 您好!
                                    &nbsp;&nbsp;欢迎进入管理系统
                                </h1>
                            </div>
                        </marquee>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <div class="layui-footer">
        <!-- 底部固定区域 -->
        © layui.com - 底部固定区域
    </div>
</div>

<script>
    //导航
    layui.use('element', function () {
        var element = layui.element;
        $.ajax({
            url: "${pageContext.request.contextPath}/menu/allMenu",
            success: function (data) {
                var html = "";
                //一级标题遍历
                $.each(data, function (index1, menu1) {
                    html += "<li class='layui-nav-item layui-nav-itemed'><a href='javascript:;'>" + menu1.menuName + "</a><dl class='layui-nav-child'>";
                    //二级标题遍历
                    $.each(menu1.menuList, function (index2, menu2) {
                        html += "<dd><a href='javascript:;' onclick=addTab(" + menu2.menuId + ",'" + menu2.menuName + "','" + menu2.menuUrl + "')>" + menu2.menuName + "</a></dd>";
                    });
                    html += "<dl></li>"
                });
                //写入html内容
                $("#menu").html(html);
                //渲染导航
                element.render("nav", "menu-nav");
            }
        })
    });

    //添加标签页
    function addTab(menuId, menuName, menuUrl) {
        var element = layui.element;
        if (!$("li[lay-id='" + menuId + "']").length) {
            element.tabAdd("myTab", {
                title: menuName,
                content: "<iframe id='" + menuId + "' src='${pageContext.request.contextPath}" + menuUrl + "' height='100%' width='100%'></iframe>",
                id: menuId
            })
        }
        element.on('tab(myTab)', function (data) {
            var src = $("#" + menuId).attr("src");
            $("#" + menuId).attr("src", src);
        });
        element.tabChange("myTab", menuId);
    }
</script>
</body>
</html>

